package com.hy.controller.setting;


import com.hy.common.base.RespResult;
import com.hy.common.excel.HyPropertySortExport;
import com.hy.common.log.annotation.SysOpLogAnnotation;
import com.hy.entity.dto.ProperSortDTO;
import com.hy.entity.dto.UserSearchDTO;
import com.hy.entity.pojo.HyPropertySort;
import com.hy.service.HyPropertySortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/propertySort")
public class PropertySortController {



    @Autowired
    private HyPropertySortService propertySortService;
    @Resource
    private HyPropertySortExport propertySortExport;

    @GetMapping("/showPropertySortDetail")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "查询资产类别",reqParam = "'查询条件'")
    public RespResult show(ProperSortDTO dto){
        return propertySortService.showPropertySortByDto(dto);

    }


    @PostMapping("/addPropertySort")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "添加资产",reqParam = "'类别ID：'+#sort.sortId")
    public RespResult add(@RequestBody HyPropertySort sort){

        return propertySortService.addPropertySort(sort);

    }
    @PostMapping("/update")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "修改资产",reqParam = "'类别ID：'+#sort.sortId")
    public RespResult update(@RequestBody HyPropertySort sort){

        if (sort.getDel().equals(2)){
            return RespResult.error(500,"不存在的资源");
        }
        return propertySortService.updatePropertySort(sort);

    }

    @PostMapping("/delete")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "删除资产",reqParam = "'类别ID：'+#ids")
    public  RespResult delete(Integer[] ids){
        List<Integer> integers=new ArrayList<>();
        Collections.addAll(integers,ids);
        return propertySortService.deletePropertySort(integers);

    }

    @RequestMapping("/exportExcelSmallData")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "导出类别",reqParam = "'按条件导出类别'")
    public void export(HttpServletResponse response, ProperSortDTO searchDTO){
        propertySortExport.exportWithBigData(response, "用户列表", searchDTO);
    }
    @RequestMapping("/importExcelBigData")
    @SysOpLogAnnotation(menuName = "资产类别",menuBtn = "导入类别",reqParam = "'类别导入'")
    public RespResult importExcelBigData(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request){


        return  propertySortService.importExcelBigData(multipartFile,request);
    }


}
